#ifndef OBJECT_H
#define OBJECT_H

#include <vector>
#include <map>
#include <memory>
#include <functional>

#define emit
#define slots
#define signals public

//1.原码使用方式"https://github.com/chxuan/samples/tree/master/Connect"
#define connect(sender, signal, slot) ((sender)->signal.bind(slot))

template<typename... Args>
class Slot
{
public:
    using OnFunc = std::function<void(Args&&...)>;

    Slot(const OnFunc& func) : m_func(func) {}

    void exec(Args&&... args)
    {
        m_func(std::forward<Args>(args)...);
    }

private:
    OnFunc m_func = nullptr;
};

template<typename... Args>
class Signal
{
public:
    using SlotPtr = std::shared_ptr<Slot<Args&&...>>;
    using OnFunc = std::function<void(Args&&...)>;

    void bind(const OnFunc& func)
    {
        SlotPtr s = std::make_shared<Slot<Args&&...>>(func);
        m_slotVec.emplace_back(s);
    }

    void operator()(Args&&... args)
    {
        for (auto& iter : m_slotVec)
        {
            iter->exec(std::forward<Args>(args)...);
        }
    }

private:
    std::vector<SlotPtr> m_slotVec;
};

class Object
{
public:
    explicit Object(void);
    virtual ~Object();

//    static bool connect(Object *sender, Signal *signal, Object *recver, Slot *slot);
//    static bool disconnect(Object *sender, Signal *signal, Object *recver, Slot *slot);

protected:
//    std::map<Signal> m_signalList;
};
#endif // OBJECT_H
